package com.cpr.ams.service.impl;

import com.cpr.ams.bean.Renting;
import com.cpr.ams.bean.extend.OrderExtend;
import com.cpr.ams.bean.extend.RentingExtend;
import com.cpr.ams.mapper.RentingMapper;
import com.cpr.ams.mapper.extend.RentingExtendMapper;
import com.cpr.ams.service.IRentingService;
import com.jacky.base.utils.PageVM;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RentingServiceImpl implements IRentingService {
    @Autowired
    private RentingMapper rentingMapper;
    @Autowired
    private RentingExtendMapper rentingExtendMapper;
    @Override
    public void saveOrUpdateRenting(Renting renting) {
        if (renting.getId()!=null){
            rentingMapper.updateByPrimaryKeySelective(renting);
        }else {
            rentingMapper.insertSelective(renting);
        }
    }

    @Override
    public PageVM<RentingExtend> query(Integer page, Integer pageSize, Integer tenantId, Integer roomId) {
        List<RentingExtend> list=rentingExtendMapper.query(page,pageSize,tenantId,roomId);
        long total =rentingExtendMapper.count(tenantId,roomId);
        return new PageVM<>(page, pageSize, total, list);
    }
}
